package al189rotate;

import java.util.ArrayList;
import java.util.Arrays;

public class RotateArray {

    public static void rotate(int[] nums, int k) {
        int length = nums.length;
        if(k>length){
            k %= length;
        }
        k = length - k;
        int[] temps = new int[k];
        for(int i=0; i<length+k; i++){
            if(i<k){
                temps[i] = nums[i];
            }else if (i>=k && i<length) {
                nums[i-k] = nums[i];
            }
            else if(i>=length){
                nums[i-k] = temps[i-length];
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        rotate(nums,3);
        System.out.println(Arrays.toString(nums));
    }
}
